package com.dayuanit.dy15.lesson21.demo2;

//Comparable是用来比较的元素大小的
public class Word implements Comparable {
    public char c;
    public int count;

    public Word(char c, int count) {
        this.c = c;
        this.count = count;
    }

    @Override
    public int compareTo(Object o) {
        if (o instanceof Word) {
            Word otherWord = (Word)o;
            //从小到大
//            return this.count - otherWord.count;

            //从大到小
            return otherWord.count - this.count;
        }
        throw new NullPointerException("参数错误");
    }

    @Override
    public String toString() {
        return "Word{" +
                "c=" + c +
                ", count=" + count +
                '}';
    }
}
